package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.entity.Orders;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController("AdminOrderController")
@RequestMapping("/admin/order/")
@Slf4j
@Api(tags = "管理端-订单管理接口")
public class OrderController {


    @Autowired
    private OrderService orderService;


    /**
     * 管理端-订单完成接口
     * @param id
     * @return
     */
    @PutMapping("/complete/{id}")
    @ApiOperation("管理端-订单完成接口")
    public Result CompleteOrder(@PathVariable Long id){
        orderService.CompleteOrder(id);
        return Result.success();
    }


    /**
     * 管理端-派送订单接口
     * @param id
     * @return
     */
    @PutMapping("/delivery/{id}")
    @ApiOperation("管理端-派送订单接口")
    public Result DeliveryOrder(@PathVariable Long id){
        orderService.DeliveryOrder(id);
        return Result.success();
    }


    /**
     * 管理端-订单取消接口
     * @param ordersCancelDTO
     * @return
     */
    @PutMapping("/cancel")
    @ApiOperation("管理端-订单取消接口")
    public Result CancalOrder(@RequestBody OrdersCancelDTO ordersCancelDTO) throws Exception {
        orderService.CancalOrder(ordersCancelDTO);
        return Result.success();
    }

    /**
     * 管理端-商家拒单
     * @param ordersRejectionDTO
     * @return
     */
    @PutMapping("/rejection")
    @ApiOperation("管理端-商家拒单")
    public Result RejectOrder(@RequestBody OrdersRejectionDTO ordersRejectionDTO) throws Exception {
        orderService.RejectOrder(ordersRejectionDTO);
        return Result.success();
    }

    /**
     * 管理端-商家接单接口"
     * @param ordersConfirmDTO
     * @return
     */
    @PutMapping("/confirm")
    @ApiOperation("管理端-商家接单接口")
    public Result AcceptOrder(@RequestBody OrdersConfirmDTO ordersConfirmDTO){
        orderService.AcceptOrder(ordersConfirmDTO);
        return Result.success();
    }

    /**
     * 管理端-通过订单id查询订单详情
     * @param id
     * @return
     */
    @GetMapping("/details/{id}")
    @ApiOperation("管理端-通过订单id查询订单详情")
    public Result<OrderVO> QueryOrderDetail(@PathVariable("id") Long id){
        log.info("当前输入的id是:{}",id);
        OrderVO orderVO = orderService.QueryOrderDetail(id);
        return Result.success(orderVO);
    }


    /**
     * 统计各个状态订单的数量
     * @return
     */
    @GetMapping("/statistics")
    @ApiOperation("管理端-统计各个状态订单的数量")
    public Result<OrderStatisticsVO> CountOrderStatistics(){
        OrderStatisticsVO orderStatisticsVO = orderService.CountOrderStatistics();
        return Result.success(orderStatisticsVO);
    }


    /**
     * 管理端的订单条件查询接口
     * @param ordersPageQueryDTO
     * @return
     */
    @GetMapping("/conditionSearch")
    @ApiOperation("管理端-订单条件搜索")
    public Result<PageResult> ConditionalSearch(OrdersPageQueryDTO ordersPageQueryDTO){
        PageResult pageResult = orderService.ConditionalSearch(ordersPageQueryDTO);
        return Result.success(pageResult);
    }




}
